<?php

require_once dirname(__FILE__).'/../lib/sfGuardUserGeneratorConfiguration.class.php';
require_once dirname(__FILE__).'/../lib/sfGuardUserGeneratorHelper.class.php';

/**
 * sfGuardUser actions.
 *
 * @package    sfGuardPlugin
 * @subpackage sfGuardUser
 * @author     Fabien Potencier
 * @version    SVN: $Id: actions.class.php 23319 2009-10-25 12:22:23Z Kris.Wallsmith $
 */
class sfGuardUserActions extends autoSfGuardUserActions
{
	public function executeProcessinscription ($request)
	{
		$id = $request->getParameter('id');
		$listechoix = $request->getParameter('modulecheck');
		if($listechoix)
		{
			$deleted = Doctrine_Query::create()
				  ->delete()
				  ->from('inscriptions i')
				  ->andWhere('i.id_sf_guard_user = ?',$id)
				  ->execute();
			$listemodulechoix = array();	  
			foreach ($listechoix as $choix)
			{
				if($choix)
				{
					$ins = new Inscriptions();
					$ins->setIdSfGuardUser($id);
					$ins->setIdModule($choix);
					$ins->save();
					
					$q = Doctrine_Query::create()->select('m.id,m.nom')->from('modules m')->where('m.id = ?',$choix);
					$modulechoix = $q->fetchOne();
					array_push($listemodulechoix,$modulechoix);
				}
			}
			$this->id = $id;
			$this->listechoix = $listemodulechoix;
			//$this->listechoix = $listechoix;
		}	
	}
	public function executeGestioninscription ($request)
	{
		$q = Doctrine_Query::create()->select('i.id_sf_guard_user,i.id_module')->from('inscriptions i')->groupBy('i.id_sf_guard_user');
		$this->lstinsctiption = $q->fetchArray();
		
		$results_per_page = 9;
		$first_page=1;  
		$this->pagination = new sfDoctrinePager('modules', $results_per_page);  
		$this->pagination->setQuery(Doctrine_Core::getTable('modules')->createQuery('a'));  
		$this->pagination->setPage($request->getParameter('page', $first_page));  
		$this->pagination->init();  
		$this->moduless = $this->pagination->getResults();
	}
	
	public function executeGestionprofile ($request)
	{
		
	}
	
	public function executeEdituserprofile ($request){
		
	}
	public function executeUpdateuserprofile ($request){
		$nom = $request->getParameter('nom');
		$prenom = $request->getParameter('prenom');
		$identifiant = $request->getParameter('identifiant');
		$mdp = $request->getParameter('mdp');
		$mdp_encore = $request->getParameter('mdp_encore');
		
		
		$q = Doctrine_Query::create()
		 ->update("sfGuardUser s")
		 ->set("s.first_name", "'".$prenom."'")
		 ->set("s.last_name", "'".$nom."'")
		 ->where("s.username=?",$identifiant)
		 ->execute();
		$this->setTemplate('edituserprofile');
	}
	
	public function executeModulechoisi ($request)
	{
		$id = $request->getParameter('id');
		
		 $q = Doctrine_Query::create()
		  ->from('Inscriptions i')
		  ->leftJoin('i.Modules m')
		  ->where('i.id_module = m.id')
		  ->andWhere('i.id_sf_guard_user=?',$id);
	  $this->modules = $q->fetchArray();
		
	}
	
	public function executeAdministration ($request){
		
	}
	
	
}
